package com.red.book;

import android.Manifest;
import android.content.res.Configuration;
import android.content.res.Resources;

import com.neo.duan.BaseAppApplication;

/**
 * @author neo.duan
 * @date 2018/1/15 16:08
 * @desc AppApplication
 */
public class App extends BaseAppApplication {

    /**
     * 6.0动态获取启动应用必须的权限
     */
    public static final String[] PERMISSIONS = new String[]{
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
    };

    @Override
    public String[] getPermissions() {
        return PERMISSIONS;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    /**
     * 设置app字体不随系统改变
     */
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1) {
            //非默认值
            getResources();
        }
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        //非默认值
        if (res.getConfiguration().fontScale != 1) {
            Configuration newConfig = new Configuration();
            //设置默认
            newConfig.setToDefaults();
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
}
